
package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.request.GoodsAddParam;
import com.xin.di.uav.applet.request.GoodsEditParam;
import com.xin.di.uav.applet.request.ServiceAreaAddParam;
import com.xin.di.uav.applet.request.ServiceAreaEditParam;
import com.xin.di.uav.applet.resp.ProductResp;
import com.xin.di.uav.applet.service.GoodsService;
import com.xin.di.uav.common.request.common.IdRequest;
import com.xin.di.uav.common.utils.Rs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@RequestMapping("/home/goods/")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @PostMapping("add")
    public Rs<Boolean> add(@RequestBody @Valid GoodsAddParam goodsAddParam) {
        return Rs.success(goodsService.add(goodsAddParam));
    }

//    @DeleteMapping("{id}")
//    public Rs<Boolean> delete(@PathVariable String id) {
//        return Rs.success(serviceAreaService.delete(id));
//    }

    @PutMapping("update")
    public Rs<Boolean> update(@RequestBody @Valid GoodsEditParam goodsEditParam) {
        return Rs.success(goodsService.update(goodsEditParam));
    }

    @PutMapping("update-status")
    public Rs<Boolean> updateStatus(@RequestBody @Valid IdRequest idRequest) {
        return Rs.success(goodsService.updateStatus(idRequest));
    }

//    @GetMapping("{id}")
//    public Rs<ServiceAreaPO> getById(@PathVariable String id) {
//        return Rs.success(serviceAreaService.getById(id));
//    }

    @GetMapping("list")
    public Rs<ProductResp> list(@RequestParam int page, @RequestParam int pageSize
            , @RequestParam(required = false) String name) {
        return Rs.success(goodsService.list(page, pageSize, name));
    }
}
